<template>
  <a-modal :open="open" width="1300px" :title="rowData.bh ? '修改西成药' : '新增西成药'" centered destroy-on-close @cancel="onCancel">
    <a-tabs v-model:activeKey="tabActiveKey">
      <a-tab-pane key="基本信息" tab="基本信息" />
      <a-tab-pane key="上海医保" tab="上海医保" />
      <a-tab-pane key="药品用法" tab="药品用法" />
    </a-tabs>
    <a-form v-if="tabActiveKey == '上海医保'" class="mt-2 h-[520px] form-style-flex content-start px-10" :label-col="{ style: { width: '120px' } }">
      <a-row :gutter="24">
        <a-col :span="12">
          <a-form-item label="药品统编代码">
            <a-input v-model:value="formStateSH.ucCode" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="药品采购编码">
            <a-input v-model:value="formStateSH.phCode" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="分类自负比例">
            <a-input v-model:value="formStateSH.rbmRatio" placeholder="请输入" suffix="%" />
          </a-form-item>
        </a-col>

        <a-col :span="12">
          <a-form-item label="医保限额">
            <div class="flex items-center">
              <a-switch v-model:checked="formStateSH.miLimitFlag" :un-checked-value="0" :checked-value="1" class="mr-1" />
              <a-input v-model:value="formStateSH.miLimit" class="ml-4" placeholder="请输入" />
            </div>
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="英文名称">
            <a-input v-model:value="formStateSH.engName" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <div class="flex">
            <a-form-item label="医保限定">
              <a-switch v-model:checked="formStateSH.limitFlag" :un-checked-value="0" :checked-value="1" class="mr-1" />
            </a-form-item>
            <a-form-item label="特殊高价药品">
              <a-switch v-model:checked="formStateSH.specialFlag" :un-checked-value="0" :checked-value="1" class="mr-1" />
            </a-form-item>
          </div>
        </a-col>
        <a-col :span="12" class="flex">
          <a-form-item label="项目细分">
            <a-switch v-model:checked="formStateSH.subFlag" :un-checked-value="0" :checked-value="1" class="mr-1" />
          </a-form-item>
          <a-form-item label="工伤药品">
            <a-switch v-model:checked="formStateSH.injuryFlag" :un-checked-value="0" :checked-value="1" class="mr-1" />
          </a-form-item>
          <a-form-item label="复方限定">
            <a-switch v-model:checked="formStateSH.compoundFlag" :un-checked-value="0" :checked-value="1" class="mr-1" />
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="备注">
            <a-textarea v-model:value="formStateSH.memo" :rows="5" placeholder="请输入" />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
    <a-form
      v-else
      class="mt-2 h-[520px] form-style-disabled"
      :model="formState"
      name="validate_other"
      v-bind="formItemLayout"
      :label-col="{ style: { width: '100px' } }"
    >
      <!-- <div class="link-border mb-3"><span class="ml-3">基本信息</span></div> -->
      <a-row v-if="tabActiveKey == '基本信息'" :gutter="24">
        <!-- <a-col :span="8">
          <a-form-item label="药品编号">
            <a-input v-model:value="formState.bh" placeholder="请输入" :disabled="rowData.bh ? true : false" />
          </a-form-item>
        </a-col> -->
        <a-col :span="8">
          <a-form-item :wrapper-col="{ offset: 6 }">
            <a-radio-group v-model:value="formState.xmlb" @change="getMedicalRecordTypeData(true)">
              <a-radio :value="'2'">西药</a-radio>
              <a-radio :value="'4'">中成药</a-radio>
              <!-- <a-radio :value="5">中药</a-radio> -->
            </a-radio-group>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="药品名称" v-bind="validateInfos.mc">
            <a-input v-model:value="formState.mc" placeholder="请输入" @blur="onChangeEmpName" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="商品名">
            <a-input v-model:value="formState.spm" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="通用名" v-bind="validateInfos.tym">
            <a-input v-model:value="formState.tym" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="批准文号" v-bind="validateInfos.pzwh">
            <a-input v-model:value="formState.pzwh" placeholder="请输入" />
          </a-form-item>
        </a-col>

        <a-col :span="8">
          <a-form-item label="助记码" v-bind="validateInfos.pyjm">
            <a-input v-model:value="formState.pyjm" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="第二助记码" :label-col="{ offset: 0, span: 6 }" style="margin-left: 5px" v-bind="validateInfos.zjm">
            <a-input v-model:value="formState.zjm" placeholder="请输入" />
          </a-form-item>
        </a-col>

        <a-col :span="8">
          <a-form-item label="规格" v-bind="validateInfos.gg">
            <a-input v-model:value="formState.gg" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item :wrapper-col="{ offset: 6 }" style="margin-left: 5px" v-bind="validateInfos.gyfs">
            <a-checkbox-group v-model:value="formState.gyfs" @change="onCheckBoxChange">
              <a-checkbox value="outUse">门诊供应</a-checkbox>
              <a-checkbox value="inpUse">住院供应</a-checkbox>
            </a-checkbox-group>
          </a-form-item>
        </a-col>

        <a-col :span="8">
          <a-form-item label="单位" v-bind="validateInfos.dw">
            <a-input v-model:value="formState.dw" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-row :gutter="24">
            <a-col :span="12">
              <a-form-item label="最小单位" :label-col="{ span: 13 }" style="margin-left: 5px" class="width-auto" v-bind="validateInfos.zxdw">
                <a-input v-model:value="formState.zxdw" placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item label="单位/最小单位" :label-col="{ span: 15 }" class="width-auto" style="margin-left: -7px" v-bind="validateInfos.zsb">
                <a-input-number v-model:value="formState.zsb" :disabled="unitDisabled" placeholder="请输入" />
              </a-form-item>
            </a-col>
          </a-row>
        </a-col>
        <a-col :span="8">
          <a-form-item label="最小单位规格" :label-col="{ span: 7 }" v-bind="validateInfos.zxgg">
            <a-input v-model:value="formState.zxgg" placeholder="请输入" @change="onGgChange" />
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item label="剂量单位" v-bind="validateInfos.jldw">
            <a-input v-model:value="formState.jldw" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="10">
          <a-form-item label="最小单位/剂量单位" :label-col="{ span: 10 }" class="" style="margin-left: -1px" v-bind="validateInfos.jldwzsb">
            <a-input-number v-model:value="formState.jldwzsb" :disabled="jlUnitDisabled" placeholder="请输入" class="w-full" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="药品剂型" v-bind="validateInfos.dosageId">
            <a-input v-model:value="formState.dosageName" placeholder="请输入" />
            <!-- <a-select v-model:value="formState.dosageId" placeholder="请选择">
              <a-select-option v-for="(item, index) in agentList" :key="index" :value="item.id">{{ item.dosageName }}</a-select-option>
            </a-select> -->
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="追溯码单位">
            <a-input v-model:value="formState.purchaseUnit" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="追溯码单位/单位">
            <a-input v-model:value="formState.purchaseUnitCft" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="药品类型" v-bind="validateInfos.jsyplb">
            <a-select v-model:value="formState.jsyplb" placeholder="请选择">
              <a-select-option :value="0">普通药品</a-select-option>
              <a-select-option :value="1">I类精神药品</a-select-option>
              <a-select-option :value="2">II类精神药品</a-select-option>
              <a-select-option :value="3">麻醉药品</a-select-option>
              <a-select-option :value="4">特殊药品</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="零售单价" v-bind="validateInfos.dj">
            <a-input-number v-model:value="formState.dj" placeholder="请输入" class="w-full" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="药理分类">
            <a-select v-model:value="formState.ylfl" max-tag-count="responsive" :options="pharmacologyList" placeholder="请选择" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item :wrapper-col="{ offset: 6 }">
            <a-radio-group v-model:value="formState.otcFlag">
              <a-radio :value="0">OTC非处方</a-radio>
              <a-radio :value="1">Rx处方药</a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>

        <a-col :span="8">
          <a-form-item label="安全库存量" v-bind="validateInfos.aqkc">
            <a-input-number v-model:value="formState.aqkc" placeholder="请输入" class="w-full" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="最佳库存量" v-bind="validateInfos.zjkc">
            <a-input-number v-model:value="formState.zjkc" placeholder="请输入" class="w-full" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="单位采购量" v-bind="validateInfos.dwcgl">
            <a-input-number v-model:value="formState.dwcgl" placeholder="请输入" class="w-full" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="厂家" v-bind="validateInfos.cj">
            <a-input v-model:value="formState.cj" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="产地">
            <a-input v-model:value="formState.cd" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="有效时间" v-bind="validateInfos.qgpNumber">
            <a-input v-model:value="formState.qgpNumber" placeholder="请输入">
              <template #addonAfter>
                <a-select v-model:value="formState.qgpUnit" style="width: 72px">
                  <a-select-option :value="0">年</a-select-option>
                  <a-select-option :value="1">月</a-select-option>
                  <a-select-option :value="2">天</a-select-option>
                  <a-select-option :value="3">小时</a-select-option>
                </a-select>
              </template>
            </a-input>
          </a-form-item>
        </a-col>
        <a-col :span="4">
          <a-form-item class="pl-24">
            <!-- 1：需要皮试 0:不需要皮试 -->
            <a-checkbox v-model:checked="formState.skinTestFlag" @change="onChangeSkinTest">需要皮试</a-checkbox>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="皮试用药" :required="formState.skinTestFlag">
            <SelectMedicine
              :value="{ mc: formState.skinTestDrugName, gg: formState.skinTestDrugGg, cj: formState.skinTestDrugCj }"
              :disabled="!formState.skinTestFlag"
              type="西成药"
              custom-border
              custom-input
              table-width="500"
              :search-params="{ cxxm: 1 }"
              @select="onSelectMedicine($event)"
            />
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item label="过敏类目">
            <SelectItem v-model:value="formState.allergyCode" type="DT00032" :disabled="!formState.skinTestFlag" placeholder="请选择" />
          </a-form-item>
        </a-col>
        <a-col :span="6">
          <a-form-item label="皮试有效期">
            <a-input v-model:value="formState.skinTestValid" v-input:int suffix="天" :disabled="!formState.skinTestFlag" placeholder="请输入" class="w-full" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="盒码前7位">
            <a-input v-model:value="formState.tcStdCode" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="中码前7位">
            <a-input v-model:value="formState.tcMidCode" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="箱码前7位">
            <a-input v-model:value="formState.tcBiuCode" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="24" class="flex">
          <a-form-item label="病案类别" class="w-1/3">
            <a-tree-select
              v-model:value="formState.mrCategoryId"
              :tree-data="medicalRecord"
              allow-clear
              tree-default-expand-all
              placeholder="请选择"
              tree-node-filter-prop="categroyName"
              :field-names="{
                label: 'categroyName',
                value: 'id'
              }"
            />
          </a-form-item>
          <a-form-item label="会员类别" class="w-1/3">
            <SelectMember v-model:value="formState.memberCategoryCode" />
          </a-form-item>
        </a-col>

        <a-col :span="4">
          <a-form-item class="pl-24">
            <a-checkbox v-model:checked="formState.isAntibiotics" @change="onChangeTics">抗菌药物</a-checkbox>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <!-- :required="formState.isAntibiotics" -->
          <a-form-item label="药品分类" v-bind="validateInfos.drugCategoryCode">
            <SelectItem v-model:value="formState.drugCategoryCode" type="DT00302" placeholder="请选择" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="使用级别">
            <a-radio-group v-model:value="formState.useLevel">
              <a-radio value="1">非限制</a-radio>
              <a-radio value="2">限制</a-radio>
              <a-radio value="3">特殊</a-radio>
            </a-radio-group>
          </a-form-item>
        </a-col>

        <a-col :span="24">
          <a-form-item label="使用指导">
            <a-textarea v-model:value="formState.syzd" :rows="3" placeholder="请输入" />
          </a-form-item>
        </a-col>
      </a-row>

      <a-row v-if="tabActiveKey == '药品用法'">
        <a-col v-for="(item, index) in usageList" :key="index" :span="12" class="p-2">
          <a-card :title="'用法' + (index + 1)" :bordered="true">
            <template #extra>
              <a-button type="text" danger size="small" :icon="h(DeleteOutlined)" @click="resetUsageItem(item)" />
            </template>
            <a-form-item label="给药途径" :wrapper-col="{ offset: 0 }" class="w-full">
              <a-select
                v-model:value="item.usageCode"
                placeholder="请选择"
                :options="usageOptionsList"
                :field-names="{ label: 'usageName', value: 'usageCode' }"
                allow-clear
              />
            </a-form-item>
            <a-form-item label="频次" :wrapper-col="{ offset: 0 }">
              <a-select
                v-model:value="item.frequencyCode"
                placeholder="请选择"
                :options="frequencyOptionsList"
                :field-names="{ label: 'frequencyName', value: 'frequencyCode' }"
                allow-clear
              />
            </a-form-item>
            <div class="flex w-full">
              <a-form-item label="剂量" :wrapper-col="{ offset: 0 }" class="w-1/2">
                <a-input v-model:value="item.dose" placeholder="请输入" :suffix="formState.jldw" />
              </a-form-item>
              <a-form-item label="天数" :wrapper-col="{ offset: 0 }" class="w-1/2">
                <a-input v-model:value="item.day" placeholder="请输入" />
              </a-form-item>
            </div>
          </a-card>
        </a-col>
      </a-row>
    </a-form>
    <template #footer>
      <div style="margin-top: 160px; text-align: right">
        <a-button @click="onCancel">取消</a-button>
        <a-button type="primary" @click="onOk">保存</a-button>
      </div>
    </template>
  </a-modal>
</template>
<script setup>
import { ref, watch, h, watchEffect } from 'vue'
import { DeleteOutlined } from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'
// import SelectMedicineCustom from './SelectMedicineCustom.vue'
// import SelectItem from '@/components/SelectItem'

const tabActiveKey = ref('上海医保')
const usageOptionsList = ref([])
const frequencyOptionsList = ref([])
// const agentList = ref([])
const usageList = ref([
  {
    drugCode: '',
    outOrder: 1
  },
  {
    drugCode: '',
    outOrder: 2
  },
  {
    drugCode: '',
    outOrder: 3
  },
  {
    drugCode: '',
    outOrder: 4
  }
])
const unitDisabled = ref(false)
const jlUnitDisabled = ref(false)
const medicalRecord = ref([])

const props = defineProps({
  open: {
    type: Boolean,
    default: false
  },
  pharmacologyList: {
    description: '药理分类',
    type: Array,
    default: () => []
  },
  rowData: {
    type: Object,
    default: () => ({})
  }
})

const emit = defineEmits(['update:open', 'success'])
const formState = ref({
  xmlb: '2',
  mc: '',
  spm: '',
  tym: '',
  pzwh: '',
  pyjm: '',
  zjm: '',
  gg: '',
  gyfs: '',
  outUse: 0, //门诊是否使用 0不使用  1使用
  inpUse: 0, //住院是否使用 0不使用  1使用
  dw: '',
  zxdw: '',
  zsb: '',
  zxgg: '',
  jldw: '',
  jldwzsb: '',
  dosageId: undefined,
  jsyplb: '',
  dj: '',
  ylfl: '',
  aqkc: '',
  zjkc: '',
  dwcgl: '',
  cj: '',
  cd: '',
  syzd: '',
  qgpNumber: '',
  qgpUnit: '',
  skinTestFlag: false,
  isAntibiotics: false,
  useLevel: '1',
  allergyCode: undefined,
  skinTestValid: undefined,
  mrCategoryId: '',
  skinTestDrugId: '',
  skinTestDrugName: '',
  skinTestDrugGg: '',
  skinTestDrugCj: '',
  otcFlag: '0'
})
const rulesState = ref({
  mc: [{ required: true, message: '请输入药品名称' }],
  gyfs: [{ required: true, message: '请至少选择一种供应方式', type: 'array' }],
  // spm: [{ required: true, message: '请输入商品名' }],
  tym: [{ required: true, message: '请输入通用名' }],
  pzwh: [{ required: true, message: '请输入批准文号' }],
  pyjm: [{ required: true, message: '请输入助记码' }],
  zjm: [{ required: true, message: '请输入第二助记码' }],
  gg: [{ required: true, message: '请输入规格' }],
  dw: [{ required: true, message: '请输入单位' }],
  zxdw: [{ required: true, message: '必填' }],
  zsb: [{ required: true, message: '必填' }],
  zxgg: [{ required: true, message: '请输入最小单位规格' }],
  jldw: [{ required: true, message: '请输入剂量单位' }],
  jldwzsb: [{ required: true, message: '请输入最小单位与剂量单位换算' }],
  dosageId: [{ required: true, message: '请选择药品剂型' }],
  jsyplb: [{ required: true, message: '请选择药品类型' }],
  dj: [{ required: true, message: '请输入零售单价' }],
  aqkc: [{ required: true, message: '请输入安全库存' }],
  zjkc: [{ required: true, message: '请输入最佳库存' }],
  dwcgl: [{ required: true, message: '请输入单位采购量' }],
  cj: [{ required: true, message: '请输入厂家' }],
  qgpNumber: [{ required: true, message: '请输入有效时间' }]
})
const validateInfos = ref({})
// const { isCompleted, resetFields, validateInfos } = useForm(formState, rulesState)

const getFrequencyList = async () => {
  const { data, code, msg } = await post('/operation/opex/getFrequencyMedicineDictInfoList', {})
  if (code !== 0) return message.error(msg)
  frequencyOptionsList.value = data
}
// const getAgentList = async () => {
//   const { data, code, msg } = await post('/operation/opex/getDictDosageFormSelect ', { status: 1 })
//   if (code !== 0) return message.error(msg)
//   agentList.value = data
// }

const getUsageList = async () => {
  const { data, code, msg } = await post('/operation/opex/shanghai/getTakeMedicineDictInfoList', {})
  if (code !== 0) return message.error(msg)
  usageOptionsList.value = data
}
const getUsage = async (bh) => {
  const { data, code, msg } = await post('/operation/opex/shanghai/getDictDrugDefaultUsageList', { drugCode: bh })
  if (code !== 0) return message.error(msg)
  if (data.length > 0) {
    usageList.value = data
  }
  usageList.value = usageList.value.map((item) => {
    item.drugCode = bh
    return item
  })
}

const getMedicalRecordTypeData = async (change) => {
  const { code, data } = await post('/operation/opex/shanghai/getDictMrCategoryList', { zjm: formState.value.xmlb === '4' ? '0007' : '0006' })
  if (code !== 0) return
  medicalRecord.value = data
  if (!formState.value.mrCategoryId || (data.length > 0 && change)) formState.value.mrCategoryId = data[0].id
}
const formStateSH = ref({})
const onOk = async () => {
  const res = await post('/operation/opex/shanghai/doSaveShmiDictDrug', { ...props.rowData, ...formStateSH.value })
  res.code !== 0 ? message.error(res.msg || '操作失败') : message.success('保存成功')
  emit('success')
  onCancel()
}
const onChangeEmpName = async (e) => {
  const { data, code, msg } = await post('/common/util/getPinyin', {
    name: e.target.value
  })
  if (code !== 0) return message.error(msg)
  formState.value.pyjm = data
  formState.value.zjm = data
}
const onCancel = () => {
  usageList.value = usageList.value.map((item) => {
    item.drugCode = ''
    return item
  })
  emit('update:open', false)
}
const onCheckBoxChange = (e) => {
  formState.value.outUse =
    e.filter((item) => {
      return item === 'outUse'
    }).length > 0
      ? 1
      : 0
  formState.value.inpUse =
    e.filter((item) => {
      return item === 'inpUse'
    }).length > 0
      ? 1
      : 0
  if (e.length <= 0) formState.value.gyfs = ''
}
const onChangeSkinTest = (e) => {
  if (!e.target.checked) {
    formState.value.allergyCode = undefined
    formState.value.skinTestValid = undefined
  }
}

const onChangeTics = () => {
  if (formState.value.isAntibiotics) {
    if (!formState.value.drugCategoryCode) {
      formState.value.drugCategoryCode = null
    }
    rulesState.value.drugCategoryCode = [{ required: true, message: '请选择药品分类' }]
  } else {
    delete formState.value.drugCategoryCode
    delete rulesState.value.drugCategoryCode
  }
}

const onGgChange = () => {
  if (formState.value.dw === formState.value.zxdw && formState.value.zxdw && formState.value.dw) {
    formState.value.gg = formState.value.zxgg
  }
}
const resetUsageItem = (item) => {
  item.usageCode = ''
  item.usageName = ''
  item.frequencyCode = ''
  item.frequencyName = ''
  item.dose = ''
  item.day = ''
}
const onSelectMedicine = (event) => {
  formState.value.skinTestDrugId = event.bh
  formState.value.skinTestDrugName = event.mc
  formState.value.skinTestDrugGg = event.gg
  formState.value.skinTestDrugCj = event.cj
}
watchEffect(() => {
  if (formState.value.dw === formState.value.zxdw && formState.value.zxdw && formState.value.dw) {
    formState.value.zsb = 1
    formState.value.zxgg = formState.value.gg
    unitDisabled.value = true
  } else {
    unitDisabled.value = false
  }
})
watchEffect(() => {
  if (formState.value.jldw === formState.value.zxdw && formState.value.zxdw && formState.value.jldw) {
    formState.value.jldwzsb = 1
    jlUnitDisabled.value = true
  } else {
    jlUnitDisabled.value = false
  }
})
watch(
  () => tabActiveKey.value,
  (val) => {
    if (val === '药品用法') {
      getUsageList()
      getFrequencyList()
    }
  }
)
watch(
  () => props.open,
  (val) => {
    if (val) {
      // getAgentList()
      tabActiveKey.value = '上海医保'
      if (props.rowData?.bh) {
        formStateSH.value = { ...props.rowData }
        formState.value = {
          useLevel: '1',
          ...props.rowData,
          skinTestFlag: props.rowData.skinTestFlag === 1 ? true : false,
          isAntibiotics: props.rowData.isAntibiotics === '1' ? true : false
        }
        if (!formState.value.inpUse && !formState.value.outUse) {
          formState.value.gyfs = ''
        } else {
          formState.value.gyfs = []
          if (formState.value.outUse === 1) formState.value.gyfs.push('outUse')
          if (formState.value.inpUse === 1) formState.value.gyfs.push('inpUse')
        }
        getUsage(props.rowData?.bh)
      } else {
        formState.value = { xmlb: '2', dosageId: undefined, gyfs: ['outUse'], useLevel: '1', otcFlag: 0 }
        formStateSH.value = {}
      }
    } else {
      formStateSH.value = {}
      usageList.value = [
        {
          drugCode: '',
          outOrder: 1
        },
        {
          drugCode: '',
          outOrder: 2
        },
        {
          drugCode: '',
          outOrder: 3
        },
        {
          drugCode: '',
          outOrder: 4
        }
      ]
    }
    getMedicalRecordTypeData()
    onChangeTics()
  },
  {
    immediate: true
  }
)
// 判断必填项
// const isCompletedOk = computed(() => {
//   const skinTest = formState.value.skinTestFlag ? formState.value.skinTestFlag && formState.value.skinTestFlag : true
//   // const skinTest = formState.value.skinTestFlag ? formState.value.skinTestFlag && formState.value.skinTestFlag : true

//   return skinTest
// })
</script>
<style lang="less" scoped>
.link-border::before {
  top: 4px;
  width: 4px;
  height: calc(100% - 7px);
  background: var(--primary-color);
  border-right: inherit;
}

.width-auto {
  .ant-input-number {
    width: auto !important;
  }
}
</style>
